#!/usr/bin/env python
# -*- coding: utf-8 -*-

# dialogs/default.py

# Copyright 2009-2010 Diego Hansen Hahn (aka DiegoHH) <diegohh90 [at] hotmail [dot] com>

# lazynds is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License.

# lazynds is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with lazynds. If not, see <http://www.gnu.org/licenses/>.

import gtk

def FileChooser(window, folder, extensions, mode):
    if mode == 'save':
        title = 'Salvar arquivo...'
        action = gtk.FILE_CHOOSER_ACTION_SAVE
        buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK)
    else:
        title = 'Abrir Arquivo...'
        action = gtk.FILE_CHOOSER_ACTION_OPEN
        buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK)

    chooser = gtk.FileChooserDialog(title = title,
                                    parent = window,
                                    action = action,
                                    buttons = buttons)

    chooser.set_position(gtk.WIN_POS_CENTER_ALWAYS)
    chooser.set_do_overwrite_confirmation(True)

    for filter in extensions:
        chooser.add_filter(filter[1])

    chooser.set_current_folder(folder)

    filename = None

    response = chooser.run()
    if response == gtk.RESPONSE_OK:
        filename = chooser.get_filename()
    filter = chooser.get_filter()
    folder = chooser.get_current_folder()
    chooser.destroy()

    return (filename, folder, filter)
